import java.text.NumberFormat;

import javax.swing.JOptionPane;

//answer = String.format("%.2f deg F = %.2f deg C",x,y)
//JOptionPane.showMessageDialog(null,answer)

public class NewTempConverter {
	// c = degrees Celcius to f = degrees Fehrenheit.
	// c(1.8) + 32 = f
	// f to degrees Celcius
	// (f - 32) / 1.8 = c

	public static void main(String[] args) {
		String s;
		s = JOptionPane
				.showInputDialog("Enter a tempature with decimal and 'c' or 'f' before to represent degrees C or F: ");
		System.out.println("Entered :" + s);

		if (s.startsWith("f")) {
			String newString = s.substring(1);
			double x = Double.parseDouble(newString); // x = F
			double y; // y = C
			y = (x - 32) / 1.8;

			NumberFormat nf = NumberFormat.getNumberInstance();
			nf.setMinimumFractionDigits(2);
			nf.setMaximumFractionDigits(2);
			// System.out.println(nf.format(x));
			// System.out.println(nf.format(y));
//
//			JOptionPane.showMessageDialog(null, nf.format(x) + " degrees F = "
//					+ nf.format(y) + " degrees C.");
			
			
			String answer = String.format("%.2f deg F = %.2f deg C",x,y);
			JOptionPane.showMessageDialog(null,answer);
			// System.out.println(nf.format(x) + " degrees F = " + nf.format(y)
			// +" degrees C.");

		}

		else if (s.startsWith("c")) {
			String newString = s.substring(1);
			double y = Double.parseDouble(newString); // y = C
			double x; // x = F
			x = (1.8 * y) + 32.0;

			NumberFormat nf = NumberFormat.getNumberInstance();
			nf.setMinimumFractionDigits(2);
			nf.setMaximumFractionDigits(2);
			// System.out.println(nf.format(x));
			// System.out.println(nf.format(y));
//			JOptionPane.showMessageDialog(null, nf.format(y) + "degrees C = "
//					+ nf.format(x) + " degrees F.");
			
			String answer = String.format("%.2f deg C = %.2f deg F",y,x);
			JOptionPane.showMessageDialog(null,answer);
			
			// System.out.println(nf.format(y) + " degrees C = " + nf.format(x)
			// + " degrees F.");
		} else {
			JOptionPane.showMessageDialog(null, "NOPE! That will not work!");
		}

		// if(f);
		// //F to C
		// else;
		// //C to F

		// NumberFormat nf =NumberFormat.getNumberInstance();
		// nf.setMinimumFractionDigits(2);
		// nf.setMaximumFractionDigits(2);
		// System.out.println(nf.format(x));

	}
}
